package com.txc.cloud.auth.common.security;

import com.txc.common.global.result.Result;
import com.txc.common.global.result.ResultCode;
import com.txc.common.utils.supply.HttpServletResponseUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 没有权限处理器
 *
 * @ClassName: AuthAccessDeniedHandler
 * @Author: TXC
 * @Date: 2023-07-31 15:43
 **/
@Component
public class AuthAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response,
                       AccessDeniedException accessDeniedException) throws IOException, ServletException {
        HttpServletResponseUtil.out(response, Result.fail(ResultCode.NO_PERMISSION));
    }
}
